package com.framework.core.exception;

import android.text.TextUtils;

/**
 * @author shenmengchao
 * @version 1.0.0
 * @date 2017/7/23
 * @description
 */

public class AppException extends BaseException {

    public final static String RESPONSE_CODE_USER_NOT_EXIST = "1001";      //用户不存在
    public final static String RESPONSE_CODE_EMAIL_IS_NULL = "1002";      //邮箱为空
    public final static String RESPONSE_CODE_EMAIL_USED = "1003";      //邮箱已注册
    public final static String RESPONSE_CODE_OLD_PWD_EMPTY = "1004";      //旧密码为空
    public final static String RESPONSE_CODE_OLD_PWD_ERROR = "1005";      //旧密码错误
    public final static String RESPONSE_CODE_PWD_EMPTY = "1006";      //密码为空
    public final static String RESPONSE_CODE_REPEAT_PWD_IS_NULL = "1007";      //重复密码为空
    public final static String RESPONSE_CODE_REPEAT_PWD_NOT_EQUAL_PWD = "1008";      //两次密码不一致
    public final static String RESPONSE_CODE_NO_AUTH_DEL_OTHER_POST = "1010";      //无权删除他人post
    public final static String RESPONSE_CODE_COMMENT_NOT_EXIST = "1011";      //评论不存在
    public final static String RESPONSE_CODE_NO_AUTH_DEL_OTHER_COMMENT = "1012";      //无权删除他人评论
    public final static String RESPONSE_CODE_PWD_ERROR = "1013";      //密码错误
    public final static String RESPONSE_CODE_INVITE_CODE_NOT_EXIST = "1014";      //邀请码不存在
    public final static String RESPONSE_CODE_USER_IS_DELETED = "1015";      //用户被管理员删除
    public final static String RESPONSE_CODE_USER_IS_FORBID = "10070";      //账号已被禁用


    public AppException(String errCode, String errMsg) {
        super(errCode, errMsg);
    }

    public AppException(String errCode) {
        super(errCode, "");
    }

    @Override
    public String getMessage() {
        if (!TextUtils.isEmpty(getErrMsg())) {
            return getErrMsg();
        }
        String errMsg = "";
        switch (getErrCode()) {
            case RESPONSE_CODE_USER_NOT_EXIST:
                errMsg = "用户不存在";
                break;
            case RESPONSE_CODE_EMAIL_IS_NULL:
                errMsg = "邮箱为空";
                break;
            case RESPONSE_CODE_EMAIL_USED:
                errMsg = "邮箱已注册";
                break;
            case RESPONSE_CODE_OLD_PWD_EMPTY:
                errMsg = "旧密码为空";
                break;
            case RESPONSE_CODE_OLD_PWD_ERROR:
                errMsg = "旧密码错误";
                break;
            case RESPONSE_CODE_PWD_EMPTY:
                errMsg = "密码为空";
                break;
            case RESPONSE_CODE_REPEAT_PWD_IS_NULL:
                errMsg = "重复密码为空";
                break;
            case RESPONSE_CODE_REPEAT_PWD_NOT_EQUAL_PWD:
                errMsg = "两次密码不一致";
                break;
            case RESPONSE_CODE_NO_AUTH_DEL_OTHER_POST:
                errMsg = "无权删除他人post";
                break;
            case RESPONSE_CODE_COMMENT_NOT_EXIST:
                errMsg = "评论不存在";
                break;
            case RESPONSE_CODE_NO_AUTH_DEL_OTHER_COMMENT:
                errMsg = "无权删除他人评论";
                break;
            case RESPONSE_CODE_PWD_ERROR:
                errMsg = "密码错误";
                break;
            case RESPONSE_CODE_INVITE_CODE_NOT_EXIST:
                errMsg = "邀请码不存在";
                break;
            case RESPONSE_CODE_USER_IS_DELETED:
                errMsg = "用户被管理员删除";
                break;
            case RESPONSE_CODE_USER_IS_FORBID:
                errMsg = "账号已被禁用";
                break;
            default:
                break;
        }
        return errMsg;
    }
}
